resource "google_pubsub_schema" "<%= ctx[:primary_resource_id] %>" {
  name = "<%= ctx[:vars]['schema_name'] %>"
  type = "AVRO"
  definition = "{\n  \"type\" : \"record\",\n  \"name\" : \"Avro\",\n  \"fields\" : [\n    {\n      \"name\" : \"StringField\",\n      \"type\" : \"string\"\n    },\n    {\n      \"name\" : \"IntField\",\n      \"type\" : \"int\"\n    }\n  ]\n}\n"
}

resource "google_pubsub_topic" "<%= ctx[:primary_resource_id] %>" {
  name = "<%= ctx[:vars]['topic_name'] %>"

  depends_on = [google_pubsub_schema.<%= ctx[:primary_resource_id] %>]
  schema_settings {
    schema = "projects/<%= ctx[:test_env_vars]['project_name'] %>/schemas/<%= ctx[:vars]['schema_name'] %>"
    encoding = "JSON"
  }
}